Skip to content

audio: add dynamic playback and capture route selection - #613

Open
Srikanth Muppandam (smuppand) wants to merge 5 commits into
qualcomm-linux:mainfrom
smuppand:audio-route-selection
Open

Srikanth Muppandam (smuppand) wants to merge 5 commits into
qualcomm-linux:mainfrom
smuppand:audio-route-selection

Conversation

@smuppand

Copy link
Copy Markdown
Contributor

Add runtime audio-route discovery without hard-coded card, PCM, sink, or source names.

Changes

  • Automatically select playback routes in this order:
    • Speakers
    • Headphones/headset
  • Automatically select capture routes in this order:
    • Built-in microphone
    • Headset microphone
  • Support explicit speaker, headset, mic, and headset-mic overrides.
  • Validate explicit routes against discovered runtime capabilities.
  • Discover routes through PipeWire, PulseAudio, ALSA, and UCM.
  • Apply the same routing model to:
    • AudioPlayback
    • AudioRecord
    • AudioLoopback
  • Improve direct ALSA fallback and diagnostics.
  • Accept valid RIFF chunks following WAV audio data.
  • Preserve portability across Yocto, Debian, Ubuntu, and other supported distributions.

Result handling

  • Explicitly requested unavailable routes report an actionable FAIL.
  • Automatic discovery reports SKIP when no usable physical route is available.
  • Functional playback, recording, and loopback failures remain FAIL.

Fixes #454

Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
chunk_id = chunk_header[0:4]
chunk_size = struct.unpack_from("<I", chunk_header, 4)[0]
next_offset = offset + 8 + chunk_size + (chunk_size & 1)
if next_offset > file_bytes:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important calculation is: next_offset = offset + 8 + chunk_size + (chunk_size & 1)

where:

  • 8 = 4-byte chunk ID + 4-byte size
  • chunk_size = payload length
  • chunk_size & 1 = 1 when payload length is odd, otherwise 0

One robustness improvement

Because _read_exact() may raise an exception if the file is unexpectedly truncated or changes after file_bytes was obtained, you could defensively handle that case:

try:
chunk_header = _read_exact(handle, 8)
except (EOFError, OSError):
return False, tuple(chunk_names)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking the chunk alignment. Yes, the calculation includes the 8-byte header and the padding byte for an odd-sized payload.

For the truncation case, _read_exact() raises WavValidationError, not EOFError. That exception, along with OSError from reading or seeking, already propagates through parse_wave() to the CLI exception handler, which emits a structured ERROR and returns exit code 2 rather than an unhandled traceback.

I would retain that propagation here. Returning False instead would classify the problem as an unrecognized trailing-chunk layout, which the caller treats as a warning, potentially allowing validation to pass despite an I/O failure. Also, the proposed except (EOFError, OSError) would not catch this helper's short-read exception. No additional catch is needed for the reported CLI failure path.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audio test procedures changed for Hamoa ubuntu

2 participants